library(ggplot2)

setwd("/Users/moch/Dropbox/TFA_analysis/APSR Replication/R Files/CoefficientsforFigures")
dem <- read.csv("demographics.csv",header=T, stringsAsFactors=FALSE)
dem$pe <- dem$c1
dem$se <- dem$c2
dem$lb <- dem$pe- 1.96*dem$se
dem$ub <- dem$pe+ 1.96*dem$se

#Category Factors
dem$col <- factor (dem$c3, levels=1)
dem$group <- factor(dem$c4,levels=c(13,12,11,10,9,8,7,6,5,4,3,2,1),
                    labels=c("Age","Female","White","College GPA",
                             "Undergraduate School Selectivity","Parental Education","Received Pell Grant",
                             "Upper Class","Upper Middle Class","Lower Middle Class","Upper Lower Class",
                             "Lower Class","Identify With Religion")[13:1])

f1 = ggplot(data = dem, aes(x = group, y = pe, width=0.5,ymin = lb, ymax = ub, color=col))

f1 = f1 + geom_pointrange(size=0.25, position = position_dodge(width=.5))
f1 = f1 + scale_shape_manual(values=c(22,22))  
f1 = f1 + scale_fill_manual(values=c("black","black"))

#Error Bars
f1 = f1+ geom_errorbar(aes(ymin=dem$pe- dem$se, ymax=dem$pe+ dem$se), width=.1)

f1 = f1 + coord_flip()
f1 = f1 + geom_hline(yintercept=0, linetype="longdash", size=0.5)
f1 = f1 + labs( y= "Treatment Effect", x = "Dependent Variable", color = "Category")

#Limits - Set this to whatever you'd like limits to be.
#f1 = f1 + scale_y_continuous(limits = c(-0.2,0.2))

#Theme
f1 =f1+ theme(plot.background= element_rect(fill="grey100"),
              panel.background= element_rect(fill="grey100", color= "grey75"),
              panel.grid.major = element_line(color= "grey75"),
              panel.grid.minor = element_line(color= "grey80"),
              panel.grid.major.y = element_blank(),
              panel.grid.minor.y = element_blank(),
              panel.spacing.x = unit(12,"point"),
              legend.position = c(-0.9,0.15),
              legend.background = element_rect(fill="grey95")
              )


  
print(f1)